package org.csu.mybigpro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.csu.mybigpro.domain.Assignment;
import org.csu.mybigpro.domain.Survey;
import org.csu.mybigpro.persistence.SurveyMapper;
import org.csu.mybigpro.service.SurveyService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SurveyServiceImpl implements SurveyService {

    @Resource
    private SurveyMapper surveyMapper;

    @Override
    public boolean saveSurvey(Survey survey) {
        return surveyMapper.insert(survey) > 0;
    }

    @Override
    public boolean updateSurvey(Survey survey) {
        return surveyMapper.updateById(survey) > 0;
    }

    @Override
    public boolean deleteSurveyById(Long id) {
        return surveyMapper.deleteById(id) > 0;
    }

    @Override
    public Survey getSurveyById(Long id) {
        return surveyMapper.selectById(id);
    }

    @Override
    public List<Survey> getSurveyByTitle(String title) {
        QueryWrapper<Survey> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("title", title);
        return surveyMapper.selectList(queryWrapper);
    }

    @Override
    public List<Survey> getAllSurveys() {
        return surveyMapper.selectList(null);
    }

}
